In building C of ADA University, one
prepares a very tasty and healthy multivitamin juice. One dose of juice
requires a apples, b pears, and c oranges. However, there
is bad luck – you must bring the fruits for juice with you!
Huseyn likes multivitamin juice very much.
He currently has x apples, y pears, and z oranges. What is
the maximum number of juice doses he can order?
Input. The first line contains three integers a, b,
and c. The second line contains three integers x, y, and z.
All numbers are non-negative integers not greater than 109.
Output. Print the largest number of juice doses that Huseyn
can order.
Sample
input |
Sample
output |
1 2 6 3 8 15 |
2 |
conditional statement
Algorithm analysis
Since one dose of juice requires a apples,
and Huseyn has x apples, he can only make at most x / a doses.
If the same logic is applied to pears and oranges, it turns out that Huseyn can
make no more than y / b and no more than z / c doses. So,
the answer is
min(x / a, y / b,
z / c)
Algorithm realization
Read
the input data.
scanf("%d %d %d", &a, &b, &c);
scanf("%d %d %d", &x, &y, &z);
Find res = min(x / a, y / b,
z / c).
res = x / a;
if (y / b < res) res = y / b;
if (z / c < res) res = z / c;
Print
the answer.
printf("%d\n", res);
Java realization
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int a = con.nextInt();
int b = con.nextInt();
int c = con.nextInt();
int x = con.nextInt();
int y = con.nextInt();
int z = con.nextInt();
int res = x / a;
if (y / b < res) res = y / b;
if (z / c < res) res = z / c;
System.out.println(res);
con.close();
}
}
Python realization
a, b, c = map(int, input().split())
x, y, z = map(int, input().split())
print(min(x // a, y // b, z // c))